home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / format / rfc2x400trc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  4.7 KB  |  203 lines

  1. /* rfc2x400trace.c: converts an RFC string to an x400 trace via rfc 1138 */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/format/RCS/rfc2x400trc.c,v 6.0 1991/12/18 20:22:06 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/format/RCS/rfc2x400trc.c,v 6.0 1991/12/18 20:22:06 jpo Rel $
  9.  *
  10.  * $Log: rfc2x400trc.c,v $
  11.  * Revision 6.0  1991/12/18  20:22:06  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "mta.h"
  20.  
  21. extern char    *compress();
  22. static int     do_md_mta(),
  23.         do_deferred(),
  24.         do_converted(),
  25.         do_attempt_md_mta(),
  26.         do_arrival(),
  27.         do_actions();
  28.  
  29. #define MATCH(a,b)    (lexnequ((a),(b),strlen(b)) == 0)
  30.  
  31.  
  32. int rfc2x400trace (trace, str)
  33. Trace    *trace;
  34. char    *str;
  35. {
  36.     /* see sect 5.3.7 in 1148 */
  37.  
  38.     char    *start, *end, *tmp = strdup(str);
  39.     int    result = OK;
  40.     PP_DBG (("Lib/rfc2x400trace (%s)", str));
  41.     
  42.     start = tmp;
  43.     
  44.     while (result == OK && start !=  NULLCP && *start != '\0') {
  45.         if ((end = index (start, ';')) != NULLCP) 
  46.             *end++ = '\0';
  47.         (void) compress (start, start);
  48.         if (MATCH(start, "by"))
  49.             /* md and mta bit */
  50.             result = do_md_mta(trace, start);
  51.         else if (MATCH(start, "deferred until"))
  52.             /* deffered delivery time */
  53.             result = do_deferred (trace, start);
  54.         else if (MATCH(start, "converted"))
  55.             /* converted eits */
  56.             result = do_converted(trace, start);
  57.         else if (MATCH(start, "attempted"))
  58.             /* attempted md and mta */
  59.             result = do_attempt_md_mta(trace, start);
  60.         else if (end == NULLCP) 
  61.             /* arrival-time */
  62.             result = do_arrival(trace, start);
  63.         else 
  64.             /* action-list */
  65.             result = do_actions (trace, start);
  66.         start = end;
  67.     }
  68.     free(tmp);
  69.     if (trace->trace_DomSinfo.dsi_time == NULL)
  70.         trace->trace_DomSinfo.dsi_time = utcnow ();
  71.     return result;
  72. }
  73.  
  74. static int do_md_mta (trace, start)
  75. Trace    *trace;
  76. char    *start;
  77. {
  78.     char    *end;
  79.     PP_DBG (("Lib/rfc2x400trace/do_md_mta (%s)", start));
  80.     start += strlen("by");
  81.     
  82.     while (isspace(*start)) start++;
  83.     
  84.     if (MATCH (start, "mta ")) {
  85.         start += strlen("mta ");
  86.         while (isspace(*start)) start++;
  87.         end = start;
  88.         while (*end != ' ') end++;
  89.         *end = '\0';
  90.         trace -> trace_mta = strdup(start);
  91.         start = end+1;
  92.         while (isspace(*start)) start++;
  93.         if (!MATCH (start, "in "))
  94.             return NOTOK;
  95.         start += strlen("in ");
  96.         while (isspace(*start)) start++;
  97.     }
  98.     
  99.     return rfc2x400globalid (&trace -> trace_DomId, start);
  100. }
  101.          
  102. static int do_deferred (trace, start)
  103. Trace    *trace;
  104. char    *start;
  105. {
  106.     PP_DBG (("Lib/rfc2x400trace/do_deferred (%s)", start));
  107.     start += strlen("deferred until");
  108.     while (isspace(*start)) start++;
  109.     
  110.     return rfc2UTC (start, &trace->trace_DomSinfo.dsi_deferred);
  111. }
  112.  
  113. static int do_converted (trace, start)
  114. Trace    *trace;
  115. char    *start;
  116. {
  117.     char    *end;
  118.     PP_DBG (("Lib/rfc2x400trace/do_converted (%s)", start));
  119.     if ((start = index(start, '(')) == NULLCP)
  120.         return NOTOK;
  121.  
  122.     start++;
  123.     if ((end = index(start, ')')) == NULLCP)
  124.         return NOTOK;
  125.     *end = '\0';
  126.  
  127.     return rfc2encinfo (&trace -> trace_DomSinfo.dsi_converted, start);
  128. }
  129.  
  130. static int do_attempt_md_mta(trace, start)
  131. Trace    *trace;
  132. char    *start;
  133. {
  134.     char    *end;
  135.  
  136.     PP_DBG (("Lib/rfc2x400trace/do_attempt_md_mta (%s)", start));
  137.  
  138.     start += strlen("attempted");
  139.     
  140.     while (isspace(*start)) start++;
  141.     
  142.     if (MATCH (start, "mta ")) {
  143.         start += strlen("mta ");
  144.         while (isspace(*start)) start++;
  145.         end = start;
  146.         while (*end != ' ') end++;
  147.         *end = '\0';
  148.         trace -> trace_DomSinfo.dsi_attempted_mta = strdup(start);
  149.         start = end+1;
  150.         while (isspace(*start)) start++;
  151.         if (!MATCH(start, "in "))
  152.             return NOTOK;
  153.         start += strlen("in ");
  154.         while (isspace(*start)) start++;
  155.     }
  156.     
  157.     return rfc2x400globalid (&trace -> trace_DomSinfo.dsi_attempted_md,
  158.                  start);
  159. }
  160.     
  161. static int do_actions (trace, start)
  162. Trace    *trace;
  163. char    *start;
  164. {
  165.  
  166.     PP_DBG (("Lib/rfc2x400trace/do_actions (%s)", start));
  167.  
  168.     while (start != NULLCP && *start != '\0') {
  169.         while (isspace(*start)) start++;
  170.         if (MATCH(start, "relayed")) {
  171.             trace -> trace_DomSinfo.dsi_action = ACTION_RELAYED;
  172.             start += strlen("relayed");
  173.         } else if (MATCH(start, "rerouted")) {
  174.             trace -> trace_DomSinfo.dsi_action = ACTION_ROUTED;
  175.             start += strlen("rerouted");
  176.         } else if (MATCH(start, "redirected")) {
  177.             trace -> trace_DomSinfo.dsi_other_actions 
  178.                 = trace -> trace_DomSinfo.dsi_other_actions 
  179.                     | ACTION_REDIRECTED;
  180.             start += strlen("redirected");
  181.         } else if (MATCH (start, "expanded")) {
  182.             trace -> trace_DomSinfo.dsi_other_actions 
  183.                 = trace -> trace_DomSinfo.dsi_other_actions
  184.                     | ACTION_EXPANDED;
  185.             start += strlen("expanded");
  186.         } else {
  187.             PP_TRACE(("Unknown action in x400 trace '%s'", start));
  188.             return NOTOK;
  189.         }
  190.         while (isspace(*start)) start++;
  191.     }
  192.     return OK;
  193. }
  194.             
  195. static int do_arrival (trace, start)
  196. Trace    *trace;
  197. char    *start;
  198. {
  199.     PP_DBG (("Lib/rfc2x400trace/do_arrival (%s)", start));
  200.  
  201.     return rfc2UTC (start, &trace->trace_DomSinfo.dsi_time);
  202. }
  203.